package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.entity.PetShop;
import com.example.pojo.vo.PetShopHotVo;
import com.example.pojo.vo.PetShopQueryVo;
import com.example.service.PetShopService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 宠物店 controller 层
 */
@RestController
@RequestMapping("/petShop")
public class PetShopController {

    @Resource
    private PetShopService petShopService;

    @PostMapping("/add")
    public Result add(@RequestBody PetShop petShop) {
        this.petShopService.add(petShop);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            PetShop petShop
    ) {
        PageResult<PetShopQueryVo> pageResult = this.petShopService.pageQuery(pageNum, pageSize, petShop);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        PetShop petShop = this.petShopService.queryById(id);
        return Result.success(petShop);
    }

    @GetMapping("/query/all")
    public Result queryAll(PetShop petShop) {
        List<PetShop> petShopList = this.petShopService.queryAll(petShop);
        return Result.success(petShopList);
    }

    @PutMapping("/update")
    public Result update(@RequestBody PetShop petShop) {
        this.petShopService.update(petShop);
        return Result.success();
    }

    @PutMapping("/identify/submit")
    private Result submitIdentify(@RequestBody PetShop petShop) {
        this.petShopService.submitIdentify(petShop);
        return Result.success();
    }

    @PutMapping("/identify/audit")
    public Result identify(@RequestBody PetShop petShop) {
        this.petShopService.auditIdentify(petShop);
        return Result.success();
    }

    @GetMapping("/hot")
    public Result queryHotPetShop() {
        List<PetShopHotVo> petShopList = this.petShopService.countAllPetShopSale();
        return Result.success(petShopList.subList(0, Math.min(petShopList.size(), 10)));
    }
}
